package com.bbc.fragment;

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.ImageView;

import com.bbc.R;
import com.bbc.base.BaseFragment;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2017/9/28.
 */

public class TestFragment extends BaseFragment {

    private ImageView mIvImse;

    @Override
    protected void setListeners() {

    }

    @Override
    protected void initData() {
        String[] name = new String[]{"b", "a"};
        Observable.just("1", "2", "3")
                .observeOn(AndroidSchedulers.mainThread())
                .observeOn(Schedulers.io())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull String s) {
                        Log.v("cbf", "s==" + s);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
        final int resours = R.mipmap.pic;
//        final ImageView imageView = new ImageView(getContext());
        Observable.create(new ObservableOnSubscribe<Drawable>() {
            @Override
            public void subscribe(@NonNull ObservableEmitter<Drawable> subscribe) throws Exception {
                Drawable drawable = getContext().getResources().getDrawable(resours);
                subscribe.onNext(drawable);
                subscribe.onComplete();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<Drawable>() {//指定回调
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Drawable drawable) {
//                        mIvImse.setImageDrawable(drawable);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    @Override
    protected void findViewId() {
//        mIvImse = mView.findViewById(R.id.iv_observer);
    }

    @Override
    protected int getViewLayou() {
        return R.layout.fragment_test;
    }
}
